<template>
  <div class="content-box">
    <nav-title title="职称信息" />
    
    <edit-line label="名称" :important="true" v-model="qualty.cName"></edit-line>
    <edit-option-line label="等级" :important="true" :vals="cpqTypes" v-model="qualty.cPfqType"></edit-option-line>
    <edit-line label="评定机构" v-model="qualty.cCompany"></edit-line>
    <edit-date-line :important="true" label="评定日期" v-model="qualty.cDate"></edit-date-line>
    <edit-line label="证书编号" v-model="qualty.cZsbh"></edit-line>
    <edit-date-line label="到期日期" v-model="qualty.cDate1"></edit-date-line>
    <edit-option-line label="职称类别" :vals="cZgzsTypes" v-model="qualty.cZgzsType"></edit-option-line>
    

    <div class="btn_region">
      <div class="submit-btn" @click="save">保存</div>
      <div class="remove-btn" @click="remove"> 删除 </div>
    </div>
    <div stype="width:100%;height:30px">&nbsp;</div>
  </div>

</template>

<script>
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditDateLine from '../../../../components/basic/EditDateLine'
import EditOptionLine from '../../../../components/basic/EditOptionLine'
import { saveQualification,delQualification,getDicItem } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    EditLine, EditDateLine, EditOptionLine
  },
  data() {
    return {
      qualty:{
        rsHireId: '',
      },
      qualDel:{
        rsHireId: '',
        cSeqno: ''
      },
      cpqTypes:[],
      cZgzsTypes:[]
    }
  },
  created() {
    this.getQal()
    if(this.$store.state.hid){
      this.qualty.rsHireId = this.$store.state.hid
      this.qualDel.rsHireId = this.$store.state.hid
    }
  },
  mounted() {
      CommonUtil.loadDic(this.cpqTypes, 'C_PFQ_TYPE', "xlatshortname","fieldvalue");//职称等级
      CommonUtil.loadDic(this.cZgzsTypes, 'C_ZGZS_TYPE', "xlatshortname","fieldvalue");//职称等级
  },
  methods: {
    save() {
      const that = this
      if(!CommonUtil.valid(this, this.qualty,"cName","请输入名称") 
        || !CommonUtil.valid(this, this.qualty,"cDate","请选择评定日期") 
        || !CommonUtil.valid(this, this.qualty,"cPfqType","请选择职称等级") 
        ){
        return;
      }
      if(this.qualty.cDate && this.qualty.cDate1 && this.qualty.cDate >= this.qualty.cDate1) {
        this.$vux.alert.show({
            title: '提示',
            content: '请填写正确的评定和到期日期',
        })
        return;
      }
      saveQualification(json2Form(this.qualty)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {

      const _this = this;
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delQualification(json2Form(_this.qualDel)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                  _this.$router.push('/informationCollection/userInfo');
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '提示',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })
          }
        })
    },
    getQal() {
      if(this.$route.params.qualt){
        this.qualty = this.$route.params.qualt
        this.qualDel.cSeqno = this.$route.params.qualt.cSeqno
        console.log(this.qualty)
      }
      CommonUtil.fillDateEmpty(this.qualty, ['cDate','cDate1'])
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
